const baseConfig = require('../base-config')
const ResponseModel = require('../models/response-model')
const fs = require('fs')
const path = require('path')

module.exports = {
    // 
    'get::/common/listFolders': async (ctx) => {
        const parentFolder = ctx.request.query.path || baseConfig.managePath
        const childs = fs.readdirSync(parentFolder, { withFileTypes: true })
        const folders = childs.filter(child => {
            return child.isDirectory()
        })
        ctx.response.body = ResponseModel.success(
            folders.map(f => {
                return {
                    'title': f.name,
                    'key': path.resolve(parentFolder, f.name)
                }
            })
        )
    },
}
  